home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / corewars / aoutput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-14  |  1.1 KB  |  44 lines

  1. /*    Copyrighted (C) 1989 by Na Choon Piaw.  All rights reserved       */
  2.  
  3.  
  4.  
  5. /*    This program and documentation is Public Domain, and may be      */
  6. /*    distributed and copied by everyone provided this header          */
  7. /*    remains intact                              */
  8.  
  9. /* output.c --- output routine for the asssembler.
  10.    11/25/88  --- NCP                             */
  11.  
  12. /* algorithm:
  13.    1.    write number of instructions into file
  14.    2.    write code number of start instruction
  15.    3.    while there are still instructions do
  16.    4.        write instruction n
  17.    5.   end
  18. */
  19. #include "assem.h"
  20. #include <stdio.h>
  21.  
  22. #define IO(i,j) if ((i) < (j)) { printf("error in writing file  --- output\n" \
  23.                  ); }
  24.  
  25. output(f, table, code, no)
  26. FILE    *f;        /* file to output to */
  27. tag1    table[];    /* table of symbols */
  28. memory    code[];        /* code itself */
  29. int    no;        /* number of instructions */
  30. {
  31.     int    check,    /* check on how many bytes have been written */
  32.         start;    /* starting instruction */
  33.  
  34.     check = fwrite(&no, sizeof(int), 1, f);
  35.     IO(check,1)
  36.  
  37.     start = getsym("START",table);
  38.     check = fwrite(&start, sizeof(int), 1, f);
  39.     IO(check,1);
  40.  
  41.     check = fwrite(code, sizeof(memory), no, f);
  42.     IO(check,no);
  43. }
  44.